// coding: utf8

#include <iostream>
#include <string>

bool is_equal(char l, char r)
{
    //std::cout << l << "," << r << std::endl;
    if (tolower(l) == tolower(r))
        return true;
    //std::cout << l << "," << r << std::endl;
    //std::cout << isalpha(l) << "," << isalpha(r) << std::endl;
    return false;
}

bool isPalindrome(std::string s)
{
    int left = 0;
    int right = s.size() - 1;
    while (left < right)
    {
        while ((left < right) && (!isalpha(s[left]) && !isalnum(s[left])))
            ++left;
        while ((left < right) && (!isalpha(s[right]) && !isalnum(s[right])))
            --right;
        if (left >= right)
            return true;
        if (!is_equal(s[left], s[right]))
            return false;
        ++left;
        --right;
    }
    return true;
}

int main()
{
    std::string str = "A man, a plan, a canal: Panama";
    std::cout << isPalindrome(str) << std::endl;
    str = "0p";
    std::cout << isPalindrome(str) << std::endl;
    str = "00";
    std::cout << isPalindrome(str) << std::endl;
    return 0;
}